<?php

namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Consult extends Controller{
    /****
     * Class register          	        校园咨询添加
     * @$image[int]    		            存储图片名称及路径
     * @$type_id['image']               图片
     * @$type_id['type']        	    1咨询，0图文
     * @$type_id['content']             内容
     * @$type_id['location']            位置
     * @$type_id['power']               观看权限：0=自己，1=所以人，2=好友
     * @$type_id['headline_id']         分类id                          审核状态：0=审核中，1=审核通过，2=拒绝通过
     * @date                	        2020/06/1 
     * @package application\index\controller\Consult
    */
    public function index(){
        $type_id = input('post.');
        if($type_id['type'] == 1){
            $data=[
                'image'         =>$type_id['image'],
                'headline_id'   =>$type_id['headline_id'],
                'type'          =>$type_id['type'],
                'content'       =>$type_id['content'],
                'location'      =>$type_id['location'],
                'power'         =>$type_id['power'],
				'headline_id'   =>$type_id['headline_id'],
				'user_id'       =>$type_id['user_id'],
                'addtime'       =>time(),
                'audit'         =>0
            ];
        }else{
            $data=[
				'image'         =>$type_id['image'],
                'headline_id'   =>$type_id['headline_id'],
                'type'          =>$type_id['type'],
                'content'       =>$type_id['content'],
                'location'      =>$type_id['location'],
                'power'         =>$type_id['power'],
				'headline_id'   =>$type_id['headline_id'],
				'user_id'       =>$type_id['user_id'],
                'addtime'       =>time(),
                'audit'         =>0
            ];
        }
        $headline_consult = Db::name('headline_consult')->insert($data);
         if($headline_consult){
            $arr = [
               'state'     => 1,
               'message'  => "请求成功"
            ];
        }else{
            $arr = [
               'state'     => 0,
               'message'  => "请求失败！"
            ];
        }
        return json($arr);
    }
	
	public function details(){
		$id = input('id');
		$headline_consult = Db::name('headline_consult')->where(['id'=>$id])->find();
		if($headline_consult){
            $arr = [
               'state'     => 1,
               'message'  => "请求成功"
            ];
        }else{
            $arr = [
               'state'     => 0,
               'message'  => "请求失败！"
            ];  
        }
        return json($arr);
	}

}
